//
//  MainViewController.m
//  sineDelv
//
//  Created by mmyy on 15/10/19.
//  Copyright (c) 2015年 mmyy. All rights reserved.
//

#import "MainViewController.h"
#import "firstVC.h"
#import "nevarByVC.h"
#import "zhuyeVC.h"
#import "RDVTabBarItem.h"
#import "MineVC.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[RDVTabBar appearance] setBackgroundColor:[UIColor purpleColor]];
    [self setUpViewControllers];
    
    // Do any additional setup after loading the view.
}
-(void)setUpViewControllers
{
    //主页
    zhuyeVC *page = [[zhuyeVC alloc] init];
    UINavigationController *pageNvc = [[UINavigationController alloc] initWithRootViewController:page];
    //粉丝列表
    nevarByVC *fans = [[nevarByVC alloc] init];
    UINavigationController *fansNvc = [[UINavigationController alloc] initWithRootViewController:fans];
    
    //我的微博
    firstVC *weibo = [[firstVC alloc] init];
    UINavigationController *weiboNvc = [[UINavigationController alloc] initWithRootViewController:weibo];
    
    //关注列表
    MineVC *attention = [[MineVC alloc] init];
    UINavigationController *attentionNvc = [[UINavigationController alloc] initWithRootViewController:attention];
    //我的
    NSArray *items = @[pageNvc, fansNvc, weiboNvc, attentionNvc];
    self.viewControllers = items;
    [[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [pageNvc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [fansNvc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [weiboNvc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [attentionNvc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [self customizeTabBarForController:self];
}
- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    NSArray *tabBarItemTitles = @[@"主页", @"附近", @"查看", @"我的"];
    
    NSArray *tabBarItemImages = @[@"tab_bar_home_icon", @"tab_bar_around_icon", @"tab_bar_discover_icon", @"tab_bar_my_icon"];
    NSInteger index = 0;
    NSDictionary *selectedTitleAttributes = nil;
    NSDictionary *unselectedTitleAttributes = nil;
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
        unselectedTitleAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName: LYRGB(147, 145, 145)};
        
        selectedTitleAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName: LYRGB(199, 57, 32)};
        
    }
    for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
        
        item.title = tabBarItemTitles[index];
        NSString *normalImageName =  [NSString stringWithFormat:@"%@.png", tabBarItemImages[index]];
        NSString *selectImageName = [NSString stringWithFormat:@"%@_current.png",tabBarItemImages[index]];
        
        UIImage *selectImage = [UIImage imageNamed:selectImageName];
        UIImage *normalImage = [UIImage imageNamed:normalImageName];
        
        [item setFinishedSelectedImage:selectImage withFinishedUnselectedImage:normalImage];
        [item setSelectedTitleAttributes:@{NSForegroundColorAttributeName:[UIColor purpleColor]}];
        [item setTitlePositionAdjustment:UIOffsetMake(0, -10)];
        [item setImagePositionAdjustment:UIOffsetMake(0, 5)];
        item.selectedTitleAttributes = selectedTitleAttributes;
        //        设置未选中状态title的字体大小和颜色
        item.unselectedTitleAttributes = unselectedTitleAttributes;
        
//        item.
        index++;
    }
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
